<?php
function user_dropdown_search() {
  global $post;
  $custom = get_post_custom($post->ID);
     $list_date = $custom["bookdate"][0]; 
    $dropdown = '';
    $dropdown_start = '<select id="select_author" onchange="document.location.href=this.options[this.selectedIndex].value;" name="select_author">';
    $dropdown_start .= sprintf('<option>%s</option>', __('Search Authors', 'adw'));
    foreach($list_date as $tag):
        $dropdown .= sprintf('<option value="%1$s">%2$s</option>', get_term_link($tag->slug, 'authors'), $tag->name);
    endforeach;
    $dropdown_end = '</select>';
    echo $dropdown_start.$dropdown.$dropdown_end;
}

function author_dropdown_search() {
    $get_tags = get_terms('authors', 'order_by=name');
    $dropdown = '';
    $dropdown_start = '<select id="select_author" onchange="document.location.href=this.options[this.selectedIndex].value;" name="select_author">';
    $dropdown_start .= sprintf('<option>%s</option>', __('Search Authors', 'adw'));
    foreach($get_tags as $tag):
        $dropdown .= sprintf('<option value="%1$s">%2$s</option>', get_term_link($tag->slug, 'authors'), $tag->name);
    endforeach;
    $dropdown_end = '</select>';
    echo $dropdown_start.$dropdown.$dropdown_end;
}

function edition_dropdown_search() {
    $get_tags = get_terms('editions', 'order_by=name');
    $dropdown = '';
    $dropdown_start = '<select id="select_edition" onchange="document.location.href=this.options[this.selectedIndex].value;" name="select_edition">';
    $dropdown_start .= sprintf('<option>%s</option>', __('Search Edition', 'adw'));
    foreach($get_tags as $tag):
        $dropdown .= sprintf('<option value="%1$s">%2$s</option>', get_term_link($tag->slug, 'editions'), $tag->name);
    endforeach;
    $dropdown_end = '</select>';
    echo $dropdown_start.$dropdown.$dropdown_end;
}

function publisher_dropdown_search() {
    $get_tags = get_terms('publishers', 'order_by=name');
    $dropdown = '';
    $dropdown_start = '<select id="select_publisher" onchange="document.location.href=this.options[this.selectedIndex].value;" name="select_publisher">';
    $dropdown_start .= sprintf('<option>%s</option>', __('Search Publishers', 'adw'));
    foreach($get_tags as $tag):
        $dropdown .= sprintf('<option value="%1$s">%2$s</option>', get_term_link($tag->slug, 'publishers'), $tag->name);
    endforeach;
    $dropdown_end = '</select>';
    echo $dropdown_start.$dropdown.$dropdown_end;
}

function classcat_dropdown_search() {
    $get_tags = get_terms('classcat', 'order_by=name');
    $dropdown = '';
    $dropdown_start = '<select id="select_classcat" onchange="document.location.href=this.options[this.selectedIndex].value;" name="select_classcat">';
    $dropdown_start .= sprintf('<option>%s</option>', __('Search Category/Class', 'adw'));
    foreach($get_tags as $tag):
        $dropdown .= sprintf('<option value="%1$s">%2$s</option>', get_term_link($tag->slug, 'classcat'), $tag->name);
    endforeach;
    $dropdown_end = '</select>';
    echo $dropdown_start.$dropdown.$dropdown_end;
}

//Search Author Widget
class author_widget extends WP_Widget {
    /** constructor */
    function author_widget() {
        parent::WP_Widget(false, $name = 'Search Authors');	
    }

    /** @see WP_Widget::widget */
    function widget($args, $instance) {		
        extract( $args );
        ?>
              <?php echo $before_widget; ?>
                  <?php echo $before_title
                      . $instance['title']
                      . $after_title; ?>
                  <?php author_dropdown_search(); ?>
              <?php echo $after_widget; ?>
        <?php
    }

    /** @see WP_Widget::update */
    function update($new_instance, $old_instance) {				
        return $new_instance;
    }

    /** @see WP_Widget::form */
    function form($instance) {				
        $title = esc_attr($instance['title']);
        ?>
            <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
        <?php 
    }

}
//Search Edition Widget
class edition_widget extends WP_Widget {
    /** constructor */
    function edition_widget() {
        parent::WP_Widget(false, $name = 'Search Editions');	
    }

    /** @see WP_Widget::widget */
    function widget($args, $instance) {		
        extract( $args );
        ?>
              <?php echo $before_widget; ?>
                  <?php echo $before_title
                      . $instance['title']
                      . $after_title; ?>
                  <?php edition_dropdown_search(); ?>
              <?php echo $after_widget; ?>
        <?php
    }

    /** @see WP_Widget::update */
    function update($new_instance, $old_instance) {				
        return $new_instance;
    }

    /** @see WP_Widget::form */
    function form($instance) {				
        $title = esc_attr($instance['title']);
        ?>
            <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
        <?php 
    }

}
//Publisher Search Widget
class publisher_widget extends WP_Widget {
    /** constructor */
    function publisher_widget() {
        parent::WP_Widget(false, $name = 'Search Publishers');	
    }

    /** @see WP_Widget::widget */
    function widget($args, $instance) {		
        extract( $args );
        ?>
              <?php echo $before_widget; ?>
                  <?php echo $before_title
                      . $instance['title']
                      . $after_title; ?>
                  <?php publisher_dropdown_search(); ?>
              <?php echo $after_widget; ?>
        <?php
    }

    /** @see WP_Widget::update */
    function update($new_instance, $old_instance) {				
        return $new_instance;
    }

    /** @see WP_Widget::form */
    function form($instance) {				
        $title = esc_attr($instance['title']);
        ?>
            <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
        <?php 
    }

}
//Category/Class Search Widget
class classcat_widget extends WP_Widget {
    /** constructor */
    function classcat_widget() {
        parent::WP_Widget(false, $name = 'Search Category/Class');	
    }

    /** @see WP_Widget::widget */
    function widget($args, $instance) {		
        extract( $args );
        ?>
              <?php echo $before_widget; ?>
                  <?php echo $before_title
                      . $instance['title']
                      . $after_title; ?>
                  <?php classcat_dropdown_search(); ?>
              <?php echo $after_widget; ?>
        <?php
    }

    /** @see WP_Widget::update */
    function update($new_instance, $old_instance) {				
        return $new_instance;
    }

    /** @see WP_Widget::form */
    function form($instance) {				
        $title = esc_attr($instance['title']);
        ?>
            <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
        <?php 
    }

}
add_action('widgets_init', create_function('', 'return register_widget("author_widget");'));
add_action('widgets_init', create_function('', 'return register_widget("edition_widget");'));
add_action('widgets_init', create_function('', 'return register_widget("publisher_widget");'));
add_action('widgets_init', create_function('', 'return register_widget("classcat_widget");'));

?>